﻿<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page import="com.cxx.purchasecharge.component.utils.ComponentConstants" %>
<%@ page import="com.cxx.purchasecharge.component.utils.MessageProperties" %>
<%@ page import="com.cxx.purchasecharge.core.model.OrderTypeCode" %>
<%@ page import="com.cxx.purchasecharge.component.bean.TimeFrame"%>

<style type="text/css">
	.css-dlg-outorder input, .css-dlg-outorder select
	{
		width: 150px;
	}
	#dlg-outorder-view input, #dlg-outorder-view select
	{
		width: 150px;
		border: none;
	}
	#dlg-outorder-preview input, #dlg-outorder-preview select
	{
		border: none;
	}
	.css-dlg-outorder
	{
		float: left;
		width: 33%;
		margin: 5px auto;
	}
	.css-dlg-outorder div
	{
		width: 155px;
		margin: 0 auto;
	}
	.css-dlg-outorder2
	{
		float: left;
		width: 100%;
		margin: 5px auto;
	}
	.css-dlg-outorder2 input, .css-dlg-outorder2 select
	{
		width: 200px;
	}
	.css-dlg-outorder2 div
	{
		width: 205px;
		margin: 0 auto;
	}
	#dlg-outorder-view label, #dlg-outorder-preview label 
	{
		color: #606B73;
	}
	#div-outorder-typecode input 
	{
		width: auto;
	}
	#div-outorder-typecode label, #div-print-outorder-setting label
	{
		cursor: pointer;
	}
</style>

<script type="text/javascript">
    var editIndex = undefined;
    function endEditing(){
        if (editIndex == undefined){return true;}
        if ($('#dg-outorderItem-new').datagrid('validateRow', editIndex)){
            var ed = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex,field:'goodsId'});
			if(ed) 
			{
				var productname = $(ed.target).combobox('getText');
				$('#dg-outorderItem-new').datagrid('getRows')[editIndex]['name'] = productname;
				$('#dg-outorderItem-new').datagrid('endEdit', editIndex);
			}
            editIndex = undefined;
            return true;
        } else {
            return false;
        }
    }
    function onClickRow(index){
        if (editIndex != index){
            if (endEditing()){
                $('#dg-outorderItem-new').datagrid('selectRow', index)
                        .datagrid('beginEdit', index);
                editIndex = index;
            } else {
                $('#dg-outorderItem-new').datagrid('selectRow', editIndex);
            }
        }
    }
    function append(){
        if (endEditing()){
			//calculateItemCount (0, 0);
			
            $('#dg-outorderItem-new').datagrid('appendRow',{id:0, goodsId:'', unit:'', unitPrice:'', amount:'', sum:'', note:'', importPrice:''});
            editIndex = $('#dg-outorderItem-new').datagrid('getRows').length-1;
            $('#dg-outorderItem-new').datagrid('selectRow', editIndex)
                    .datagrid('beginEdit', editIndex);
        }
    }
    function removeit(){
        if (editIndex == undefined){return;}
        $('#dg-outorderItem-new').datagrid('cancelEdit', editIndex)
                .datagrid('deleteRow', editIndex);
        editIndex = undefined;
		
		//calculateItemCount (0, 0);
    }
    function accept(){
        if (endEditing()){
            $('#dg-outorderItem-new').datagrid('acceptChanges');
            var allRows = $('#dg-outorderItem-new').datagrid('getRows');
            //console.log(allRows.length+' rows in current page!');
            var orderItemList = "";
            for(var i = 0; i < allRows.length; i++) 
            {
    	        //console.log(allRows[i]);
            	var orderItem = "";
    	        var item = allRows[i];
				//console.log(item);
				if(item.goodsId == '' || item.goodsId == undefined) 
				{
					throw '您选择的货物不存在！';
				}
				if(item.amount <= 0) 
				{
					throw '货物数量必须大于0！';
				}
				if(item.sum <= 0) 
				{
					throw '货物金额必须大于0！';
				}
    	        orderItem += (item.id +","+item.goodsId+","+item.unit+","+item.unitPrice+","+item.amount+","+item.note+","+ item.sum+","+ item.importPrice);
    	        orderItemList += orderItem + ";"
            }
            //console.log(orderItemList.substring(0, orderItemList.length-1));
            $('#outorderItemList').val(orderItemList);
        }
    }
    
    // order item
    function onSelectGoods (record) 
    {
    	//var goods = JSON.stringify(record);
		//console.log("editIndex--->" + editIndex);
		if (editIndex != undefined)
		{
			setValidateOutorderMsg('');
			var importPriceEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'importPrice'});
			importPriceEditor.target.val(record.importPrice);
			
			var unitEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'unit'});
			unitEditor.target.val(record.unitBean.name);
			var unitPriceEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'unitPrice'});
			unitPriceEditor.target.numberbox('setValue', record.retailPrice);
			// get latest goods retail price for specific customer
			var customerId = $('#dlg-outorder-new #fm-outorder #customerId').combobox('getValue');
			$.post('<c:url value='/outOrder/getLatestGoodsUnitPrice.html' />', {customerId:customerId, goodsId:record.id}, 
					function(result) 
					{
						var latestOrderItem = result;
						if(latestOrderItem != '') 
						{
							unitPriceEditor.target.numberbox('setValue', latestOrderItem.unitPrice);
						}
					}, 
				'json');
			
			var allRows = $('#dg-outorderItem-new').datagrid('getRows');
			if(allRows.length > 1) 
			{
				for(var i = 0; i < allRows.length; i++) 
				{
					var item = allRows[i];
					if(record.id == item.goodsId) 
					{
						$.messager.alert('警告','不要选择重复的货物!','warning');
						$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
						$('#dlg-buttons-outorder-new #preview-outorder-btn').linkbutton('disable');
						return;
					}
				}
			}
			
			// check storage whether is enough
			if('OUT' == outorder_typeCode) 
			{
				var currentStock = record.storageBean.currentStock;
				if(currentStock == 0) 
				{
					$.messager.alert('警告',record.name + '当前库存为0!','warning');
					$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
					$('#dlg-buttons-outorder-new #preview-outorder-btn').linkbutton('disable');
					return;
				}
				var amountEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'amount'});
				var amount = amountEditor.target.numberbox('getValue');
				if(amount > currentStock) 
				{
					$.messager.alert('警告','当前库存不足!','warning');
					amountEditor.target.numberbox('setValue', 0);
					$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
					$('#dlg-buttons-outorder-new #preview-outorder-btn').linkbutton('disable');
					return;
				}
			}
			$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('enable');
			$('#dlg-buttons-outorder-new #preview-outorder-btn').linkbutton('enable');
		}
    }
	function onChangeAmount (newValue, oldValue) 
	{
		//console.log("newValue-->"+newValue + " oldValue-->"+oldValue);
		if (editIndex != undefined)
		{
			if(newValue != '') 
			{
				setValidateOutorderMsg('');
				var goodsAmount = parseInteger(newValue.trim());
				// check storage whether is enough
				if('OUT' == outorder_typeCode) 
				{
					var amountEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'amount'});
					var goodsEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'goodsId'});
					var goodsText = goodsEditor.target.combobox('getText');
					if(goodsText && goodsText.lastIndexOf(' - ') > 0) 
					{
						var currentStock = goodsText.substring(goodsText.lastIndexOf('-') + 2);
						var stockNumber = parseInteger(currentStock);
						if(goodsAmount > stockNumber) 
						{
							$.messager.alert('警告','当前库存不足!','warning');
							amountEditor.target.numberbox('setValue', 0);
							$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
							$('#dlg-buttons-outorder-new #preview-outorder-btn').linkbutton('disable');
							return;
						}
					}
				}
				
				var sumEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'sum'});
				var unitPriceEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'unitPrice'});
				var unitPrice = unitPriceEditor.target.val();
				//sumEditor.target.numberbox('setValue', unitPrice * newValue);
				sumEditor.target.numberbox('setValue', new Number(newValue).mul(unitPrice));
				
				//calculateItemCount (newValue, unitPrice * newValue);
				calculateItemCount (newValue, new Number(newValue).mul(unitPrice));
				$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('enable');
				$('#dlg-buttons-outorder-new #preview-outorder-btn').linkbutton('enable');
			}
		}
	}
	function onChangeUnitPrice (newValue, oldValue) 
	{
		//console.log("newValue-->"+newValue + " oldValue-->"+oldValue);
		if (editIndex != undefined)
		{
			setValidateOutorderMsg('');
			var importPriceEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'importPrice'});
			var importPrice = parseNumber(importPriceEditor.target.val());
			if(newValue < importPrice) 
			{
				$.messager.alert('警告','单价不能低于进货价!','warning');
				$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
				$('#dlg-buttons-outorder-new #preview-outorder-btn').linkbutton('disable');
				return;
			}
			$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('enable');
			$('#dlg-buttons-outorder-new #preview-outorder-btn').linkbutton('enable');
		
			var sumEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'sum'});
			var amountEditor = $('#dg-outorderItem-new').datagrid('getEditor', {index:editIndex, field:'amount'});
			var amount = amountEditor.target.val();
			//sumEditor.target.numberbox('setValue', amount * newValue);
			sumEditor.target.numberbox('setValue', new Number(newValue).mul(amount));
			
			//calculateItemCount (amount, amount * newValue);
			calculateItemCount (amount, new Number(newValue).mul(amount));
		}
	}
	function calculateItemCount (amount, sum) 
	{
		accept();
	
		// 计算合计在页脚
		var allRows = $('#dg-outorderItem-new').datagrid('getRows');
		var totalAmount = 0;
		var totalSum = 0;
		for(var i = 0; i < allRows.length; i++) 
		{
			var item = allRows[i];
			if(item.goodsId != '' && item.goodsId != undefined) 
			{
				totalAmount += parseInt(item.amount);
				//totalSum += parseFloat(item.sum);
				totalSum = totalSum.add(item.sum);
			}
		}
		/*if(amount > 0 && sum > 0) 
		{
			totalAmount += parseInt(amount);
			//totalSum += parseFloat(sum);
			totalSum = totalSum.add(sum);
		}*/
		$('#dlg-outorder-new #fm-outorder #dg-outorderItem-new').datagrid('reloadFooter',[{goodsId:'合计', amount:totalAmount, sum:totalSum}]);
		calculateDiscount (sum);
	}
	function calculateDiscount (sum) 
	{
		var allRows = $('#dg-outorderItem-new').datagrid('getRows');
		if(allRows.length > 0) 
		{
			var totalSum = 0;
			for(var i = 0; i < allRows.length; i++) 
			{
				var item = allRows[i];
				if(item.goodsId != '' && item.goodsId != undefined) 
				{
					//totalSum += parseFloat(item.sum);
					totalSum = totalSum.add(item.sum);
				}
			}
			/*if(sum > 0) 
			{
				//totalSum += sum;
				totalSum = totalSum.add(sum);
			}*/
			var value = $('#dlg-outorder-new #fm-outorder #discount').numberbox('getValue');
			//var receivable = value * totalSum;
			var receivable = totalSum.mul(value);
			$('#dlg-outorder-new #fm-outorder #receivable').numberbox('setValue', receivable);
		}
		else 
		{
			$('#dlg-outorder-new #fm-outorder #receivable').numberbox('setValue', 0);
		}
	}
    
    var newOrderCallback = function () 
    {
    	$('#dg-outorderItem-new').datagrid('loadData', []);
    	$('#dg-outorderItem-new').datagrid('reloadFooter', []);
    	$('#dlg-outorder-new #fm-outorder #userOperated').val('${sessionScope.login_user.userId}');
    	$('#dlg-outorder-new #fm-outorder #operateUserFullName').textbox('setValue', '${sessionScope.login_user.fullName}');
    	//$('#dlg-buttons-outorder #save-outorder-btn').linkbutton('enable');
		$('#dlg-outorder-new #fm-outorder #outorder-typeCode').val(outorder_typeCode);
		$('#dlg-outorder-new #fm-outorder #discount').numberspinner('setValue', 1.00); 
		$('#dlg-outorder-new #fm-outorder #paidMoney').numberbox('setValue', 0); 
    }
    
    var viewOrderCallback = function () 
    {
		var order = $('#dg-outorder').datagrid('getSelected');
		if(order.customerBean) 
		{
			$('#dlg-outorder-view #fm-outorder #customerId').val(order.customerBean.id);
			$('#dlg-outorder-view #fm-outorder #customerName').val(order.customerBean.shortName);
			$('#dlg-outorder-view #fm-outorder #userSignedTo').val(order.customerBean.userSignedTo);
		}
		if(order.contactBean) 
		{
			$('#dlg-outorder-view #fm-outorder #contactName').val(order.contactBean.name);
			$('#dlg-outorder-view #fm-outorder #contactPhone').val(order.contactBean.phone);
		}
		
		if(order.statusCode == 'NEW') 
		{
			$('#dlg-outorder-view #fm-outorder #statusCode').val('新建');
		}
		else if(order.statusCode == 'FINISHED') 
		{
			$('#dlg-outorder-view #fm-outorder #statusCode').val('完成');
		}
		else if(order.statusCode == 'CANCEL') 
		{
			$('#dlg-outorder-view #fm-outorder #statusCode').val('取消');
		}
    	//$('#dg-outorderItem-view').datagrid('load', {orderId : $('#dg-outorder').datagrid('getSelected').id});
		loadGridData ('#dlg-outorder-view #dg-outorderItem-view', '<c:url value='/outOrder/getModelById.html' />', {orderId : order.id});
		//loadGridData ('#dg-outorderPay', '<c:url value='/outOrder/getOrderPayByOrderId.html' />', {orderId : order.id});
    	//$('#dg-outorderPay').datagrid('load', {orderId : $('#dg-outorder').datagrid('getSelected').id});
    	//$('#dlg-buttons-outorder #save-outorder-btn').linkbutton('disable');
		$('#dlg-outorder-view #order-id-span').html(order.id);
    }
    
    var updatePaidCallback = function () 
    {
    	var orderSelected = $('#dg-outorder').datagrid('getSelected');
    	var paidMoney = orderSelected.paidMoney;
    	var dealMoney = orderSelected.dealMoney;
    	if(paidMoney >= dealMoney) 
    	{
			$('#dlg-update-paid').dialog('close');
			//showSuccessMsg ('Payment has done.');
    	}
    	else 
    	{
    		$('#dlg-update-paid #paidMoney').numberbox('setValue', dealMoney-paidMoney);
    	}
    }
    
    function gotoPrintDialog () 
    {
    	//$('#dlg-outorder-view').dialog('close');
		var order = $('#dg-outorder').datagrid('getSelected');
		
		// fill print order header and footer for edit
		var createDate = order.createTime.substring(0, 10);
		$('#div-print-outorder-edit #div-outorder-header #customer').html(order.customerBean.shortName);
		if(order.contactBean) 
		{
			$('#div-print-outorder-edit #div-outorder-header #contact').val(order.contactBean.name);
			$('#div-print-outorder-edit #div-outorder-header #phone').val(order.contactBean.phone);
			$('#div-print-outorder-edit #div-outorder-header #address').val(order.contactBean.address);
		}
		$('#div-print-outorder-edit #div-outorder-header #createDate').html(createDate);
		$('#div-print-outorder-edit #div-outorder-header #orderId').html(order.id);
		$('#div-print-outorder-edit #div-outorder-footer #user').html(order.userOperated);
		$('#div-print-outorder-edit #div-outorder-footer #salesman').html(order.customerBean.userSignedTo);
		
		if('OUT' == outorder_typeCode)
		{
			$('#div-print-outorder-edit #div-print-outorder-title #titleHeader').val('<%=MessageProperties.getConfig (ComponentConstants.PRINT_ORDER_HEADER)%>');
			$('#div-print-outorder-edit #div-print-outorder-title #titleSpan').html('销售出货单');
		}
		else 
		{
			$('#div-print-outorder-edit #div-print-outorder-title #titleHeader').val('<%=MessageProperties.getConfig (ComponentConstants.PRINT_ORDER_HEADER)%>');
			$('#div-print-outorder-edit #div-print-outorder-title #titleSpan').html('销售退货单');
		}
		
		$('#dlg-print-outorder').dialog('open');
		// fill print order table
    	checkPrintPrice ($('#div-print-outorder-setting #checkMoney')[0]);
    }
	
	function printOrder () 
    {
		var titleHeader = $('#div-print-outorder-edit #div-print-outorder-title #titleHeader').val();
		var titleSpan = $('#div-print-outorder-edit #div-print-outorder-title #titleSpan').html();
		var printTitle = titleHeader + titleSpan;
		$('#div-print-outorder #div-print-outorder-title').html(printTitle);
	
		var contact = $('#div-print-outorder-edit #div-outorder-header #contact').val();
		var phone = $('#div-print-outorder-edit #div-outorder-header #phone').val();
		var address = $('#div-print-outorder-edit #div-outorder-header #address').val();
		var attachment = $('#div-print-outorder-edit #div-outorder-footer #attachment').val();
		
		var checkMoneyBox = $('#div-print-outorder-setting #checkMoney')[0];
		var order = $('#dg-outorder').datagrid('getSelected');
		if(checkMoneyBox.checked) 
		{
			var requestUrl = '<c:url value='/outOrder/printOrder.html' />';
			var param = {orderId:order.id, template:'orderPrintTemplate.html', title:printTitle, contactName:contact, contactPhone:phone, contactAddress:address, footer:attachment};
			$.post(requestUrl, param,
				function(result) 
				{
					//console.log(result);
					var $table2 = $('#div-print-outorder table');
					if($table2.get(0)) 
					{
						$table2.replaceWith($(result));
					}
					else 
					{
						$('#div-print-outorder').append($(result));
					}
					$('#div-print-outorder').print();
				}, 
			'text');
		}
		else 
		{
			var requestUrl = '<c:url value='/outOrder/printOrder.html' />';
			var param = {orderId:order.id, template:'orderPrintNoMoneyTemplate.html', title:printTitle, contactName:contact, contactPhone:phone, contactAddress:address, footer:attachment};
			$.post(requestUrl, param,
				function(result) 
				{
					//console.log(result);
					var $table2 = $('#div-print-outorder table');
					if($table2.get(0)) 
					{
						$table2.replaceWith($(result));
					}
					else 
					{
						$('#div-print-outorder').append($(result));
					}
					$('#div-print-outorder').print();
				}, 
			'text');
		}
	}
	function checkPrintPrice (checkbox) 
	{
		$('#div-print-outorder-edit').mask('加载中...');
		var order = $('#dg-outorder').datagrid('getSelected');
		if(checkbox.checked) 
		{
			var requestUrl = '<c:url value='/outOrder/getOrderItemTable.html' />';
			var param = {orderId:order.id, templateFile:'orderTableTemplate.html'};
			$.post(requestUrl, param,
    			function(result) 
    			{
    				//console.log(result);
					$('#div-print-outorder-edit').unmask();
    				
					var $table2 = $('#div-print-outorder-edit #outorder-table table');
					if($table2.get(0)) 
					{
						$table2.replaceWith($(result));
					}
					else 
					{
						$('#div-print-outorder-edit #outorder-table').append($(result));
					}
    			}, 
    		'text');
		}
		else 
		{
			var requestUrl = '<c:url value='/outOrder/getOrderItemTable.html' />';
			var param = {orderId:order.id, templateFile:'orderTableNoMoneyTemplate.html'};
			$.post(requestUrl, param,
    			function(result) 
    			{
    				//console.log(result);
					$('#div-print-outorder-edit').unmask();
    				
					var $table2 = $('#div-print-outorder-edit #outorder-table table');
					if($table2.get(0)) 
					{
						$table2.replaceWith($(result));
					}
					else 
					{
						$('#div-print-outorder-edit #outorder-table').append($(result));
					}
    			}, 
    		'text');
		}
	}
	
	function newOutOrder() 
	{
		if('OUT' == outorder_typeCode) 
		{
			newModel('#dlg-outorder-new', '新增销售出货单', '#fm-outorder', '<c:url value='/outOrder/addModel.html' />', newOrderCallback);
		}
		else 
		{
			newModel('#dlg-outorder-new', '新增销售退货单', '#fm-outorder', '<c:url value='/outOrder/addModel.html' />', newOrderCallback);
		}
		$('#dlg-outorder-new #tb-outorderList #btn-add-orderItem').linkbutton('disable');
		$('#dlg-outorder-new #tb-outorderList #btn-delete-orderItem').linkbutton('disable');
		$('#dlg-buttons-outorder-new #save-outorder-btn').linkbutton('disable');
		$('#dlg-buttons-outorder-new #preview-outorder-btn').linkbutton('disable');
	}
	function viewOutOrder()
	{
		if('OUT' == outorder_typeCode) 
		{
			var selectedRow = $('#dg-outorder').datagrid('getSelected');
			if(selectedRow) 
			{
				editModel('#dg-outorder', '#dlg-outorder-view', '查看销售出货单', '#fm-outorder', '', viewOrderCallback);
				return;
			}
			var checkedRows = $('#dg-outorder').datagrid('getChecked');
			if (checkedRows.length >= 1) 
			{
				var orderIds = "";
				for(var i = 0; i < checkedRows.length; i++) 
				{
					orderIds += (checkedRows[i].id + ";");
				}
				orderIds = orderIds.substring(0, orderIds.length-1);
				
				$('#dlg-multi-outorder-view').dialog('open').dialog('setTitle', '销售出货对账单');
				loadGridData ('#dlg-multi-outorder-view #dg-outorderItem-view', '<c:url value='/outOrder/getOrderItemsByOrderIds.html' />', {orderIds : orderIds});
			}
		}
		else 
		{
			var selectedRow = $('#dg-outorder').datagrid('getSelected');
			if(selectedRow) 
			{
				editModel('#dg-outorder', '#dlg-outorder-view', '查看销售退货单', '#fm-outorder', '', viewOrderCallback);
				return;
			}
			var checkedRows = $('#dg-outorder').datagrid('getChecked');
			if (checkedRows.length >= 1) 
			{
				var orderIds = "";
				for(var i = 0; i < checkedRows.length; i++) 
				{
					orderIds += (checkedRows[i].id + ";");
				}
				orderIds = orderIds.substring(0, orderIds.length-1);
				
				$('#dlg-multi-outorder-view').dialog('open').dialog('setTitle', '销售退货对账单');
				loadGridData ('#dlg-multi-outorder-view #dg-outorderItem-view', '<c:url value='/outOrder/getOrderItemsByOrderIds.html' />', {orderIds : orderIds});
			}
		}
	}
	function deleteOutOrder()
	{
		if('OUT' == outorder_typeCode) 
		{
			destroyMultipleModel('#dg-outorder', '销售出货单', '<c:url value='/outOrder/deleteModels.html' />');
		}
		else 
		{
			destroyMultipleModel('#dg-outorder', '销售退货单', '<c:url value='/outOrder/deleteModels.html' />');
		}
	}
	function updateOutOrderStatus() 
	{
		if('OUT' == outorder_typeCode) 
		{
			editModel('#dg-outorder', '#dlg-update-status', '编辑销售出货单状态', '#fm-outorder', '<c:url value='/outOrder/updateModel.html' />');
		}
		else 
		{
			editModel('#dg-outorder', '#dlg-update-status', '编辑销售退货单状态', '#fm-outorder', '<c:url value='/outOrder/updateModel.html' />');
		}
		var row = $('#dg-outorder').datagrid('getSelected');
		if(row) 
		{
			$('#dlg-update-status #fm-outorder #customerName').val(row.customerBean.shortName);
		}
	}
	
	var onChangeDiscount = function(value)
	{
		accept ();
		calculateDiscount (0);
	}
	var onClickOutOrderRow = function (rowIndex, rowData) 
	{
		$('#toolbar-outorder #btn-viewOutorder').linkbutton('enable');
		//$('#toolbar-outorder #btn-deleteOutorder').linkbutton('enable');
		if('OUT' == outorder_typeCode) 
		{
			if(rowData.statusCode == 'NEW') 
			{
				$('#toolbar-outorder #btn-editStatus').linkbutton('enable');
			}
			else 
			{
				$('#toolbar-outorder #btn-editStatus').linkbutton('disable');
			}
		}
	}
	var onLoadOutOrderSuccess = function (data) 
	{
		$('#toolbar-outorder #btn-viewOutorder').linkbutton('disable');
		$('#toolbar-outorder #btn-deleteOutorder').linkbutton('disable');
		$('#toolbar-outorder #btn-editStatus').linkbutton('disable');
	}
	var onCheckAllOutOrder = function(rows) 
	{
		$('#toolbar-outorder #btn-deleteOutorder').linkbutton('enable');
		$('#toolbar-outorder #btn-viewOutorder').linkbutton('enable');
	}
	var onUnCheckOutOrder = function(rowIndex,rowData) 
	{
		var rows = $('#dg-outorder').datagrid('getChecked');
		if (rows.length == 0) {
			$('#toolbar-outorder #btn-deleteOutorder').linkbutton('disable');
			$('#toolbar-outorder #btn-viewOutorder').linkbutton('disable');
		}
	}
	
	var onSelectCustomer = function(record) 
	{
		setValidateOutorderMsg('');
		//$('#dlg-outorder-new #fm-outorder #customerId').val(record.id);
		$('#dlg-outorder-new #fm-outorder #userSignedTo').textbox('setValue', record.userSignedTo);
		if(record.contactBeans.length > 0) 
		{
			$('#dlg-outorder-new #fm-outorder #contactId').val(record.contactBeans[0].id);
			$('#dlg-outorder-new #fm-outorder #contactName').textbox('setValue', record.contactBeans[0].name);
		}
		else 
		{
			$('#dlg-outorder-new #fm-outorder #contactId').val('');
			$('#dlg-outorder-new #fm-outorder #contactName').textbox('setValue', '');
		}
		$('#dlg-outorder-new #tb-outorderList #btn-add-orderItem').linkbutton('enable');
		$('#dlg-outorder-new #tb-outorderList #btn-delete-orderItem').linkbutton('enable');
	}
	var onChangeCustomer = function(newValue, oldValue) 
	{
		if(newValue == undefined) 
		{
			$('#dlg-outorder-new #fm-outorder #userSignedTo').val('');
			$('#dlg-outorder-new #fm-outorder #contactId').val('');
			$('#dlg-outorder-new #fm-outorder #contactName').val('');
			$('#dlg-outorder-new #tb-outorderList #btn-add-orderItem').linkbutton('disable');
			$('#dlg-outorder-new #tb-outorderList #btn-delete-orderItem').linkbutton('disable');
		}
	}
	var onSearchOrderById = function () 
	{
		var orderId = $('#toolbar-outorder #orderIdSearchSpan #orderId').val();
		if(orderId != '') 
		{
			var pageOptions = $('#dg-outorder').datagrid('getPager').data("pagination").options;
			var page = pageOptions.pageNumber;
			var rows = pageOptions.pageSize;
			loadGridData ('#dg-outorder', '<c:url value='/outOrder/getModelBySearchForm.html' />', {page:page, rows:rows, sort:'<%=ComponentConstants.CREATE_TIME %>', order:'asc', type:outorder_typeCode, orderId:orderId});
		}
		else 
		{
			$.messager.alert('警告','请填写查询条件!','warning');
		}
	}
	var onSelectStartDate = function (date) 
	{
		$('#toolbar-outorder #advanceSearchSpan #timeFrame').combobox('setValue', 'CUSTOMIZE');
	}
	var onSelectTimeFrame = function(record) 
	{
		var startDate = generateStartDate(record.value);
		var endDate = new Date().format("yyyy-MM-dd");
		$('#toolbar-outorder #advanceSearchSpan #startDate').datebox('setValue', startDate);
		$('#toolbar-outorder #advanceSearchSpan #endDate').datebox('setValue', endDate);
	}
	var outorder_typeCode = 'OUT';
	var getSelectedOutOrderTypeCode = function() 
	{
		var $typeCode = document.getElementsByName("outorder_typeCode_mode");
		for(var i = 0; i < $typeCode.length; i ++) 
		{
			if($typeCode[i].checked) 
			{
				outorder_typeCode = $typeCode[i].value;
				break;
			}
		}
		//console.log('outord typecode --- ' + outorder_typeCode);
	}
	
	var onSearchOrderByAdvance = function () 
	{
		var startDate = $('#toolbar-outorder #advanceSearchSpan #startDate').combo('getValue');
		var endDate = $('#toolbar-outorder #advanceSearchSpan #endDate').combo('getValue');
		var customerId = $('#toolbar-outorder #advanceSearchSpan #customerId').combo('getValue');
		if((startDate != '' && endDate == '') || (startDate == '' && endDate != '')) 
		{
			$.messager.alert('警告','开始时间和结束时间必须同时填!','warning');
			return;
		}
		if(startDate == '' && endDate == '' && customerId == '') 
		{
			$.messager.alert('警告','请填写查询条件!','warning');
			return;
		}
		//var pageOptions = $('#dg-outorder').datagrid('getPager').data("pagination").options;
		//var page = pageOptions.pageNumber;
		//var rows = pageOptions.pageSize;
		
		getSelectedOutOrderTypeCode();
		$('#dg-outorder').datagrid('reload');
		//loadGridData ('#dg-outorder', '<c:url value='/outOrder/getModelBySearchForm.html' />', {page:sortOrder.page, rows:sortOrder.rows, sort:sortOrder.sort, order:sortOrder.order, type:outorder_typeCode, startDate:startDate, endDate:endDate, customerId:customerId});
	}
	
	var onBeforeLoadOutOrder = function (param) 
	{
		//console.log('onBeforeLoadOutOrder----------------');
		//console.log(param);
		var startDate = $('#toolbar-outorder #advanceSearchSpan #startDate').combo('getValue');
		var endDate = $('#toolbar-outorder #advanceSearchSpan #endDate').combo('getValue');
		var customerId = $('#toolbar-outorder #advanceSearchSpan #customerId').combo('getValue');
		if(customerId == undefined) 
		{
			customerId = '';
		}
		if(startDate == '' && endDate == '' && customerId == '') 
		{
			var timeFrame = $('#toolbar-outorder #advanceSearchSpan #timeFrame').combo('getValue');
			startDate = generateStartDate(timeFrame);
			endDate = new Date().format("yyyy-MM-dd");
			$('#toolbar-outorder #advanceSearchSpan #startDate').datebox('setValue', startDate);
			$('#toolbar-outorder #advanceSearchSpan #endDate').datebox('setValue', endDate);
			
			startDate = $('#toolbar-outorder #advanceSearchSpan #startDate').combo('getValue');
			endDate = $('#toolbar-outorder #advanceSearchSpan #endDate').combo('getValue');
		}
		
		getSelectedOutOrderTypeCode();
		if(param.page == undefined || param.page == 0) 
		{
			param.page = 1;
		}
		$('#dg-outorder').datagrid('options').url = "<c:url value='/outOrder/getModelBySearchForm.html' />?type="+outorder_typeCode+"&startDate="+startDate+"&endDate="+endDate+"&customerId="+customerId+"&page="+param.page;
		
		return true;
	}
	var onDblClickOutOrderRow = function(rowIndex, rowData) 
	{
		viewOutOrder();
	}
	var previewOutOrder = function() 
	{
		if(!$('#dlg-outorder-new #fm-outorder').form('validate')) 
		{
			return false;
		}
		$('#dlg-buttons-outorder-preview #submit-outorder-btn').linkbutton('enable');
		try 
		{
			accept();
			$('#dlg-outorder-preview').dialog('open').dialog('setTitle', '出库单预览');
			var customerName = $('#dlg-outorder-new #fm-outorder #customerId').combobox('getText');
			$('#dlg-outorder-preview #fm-outorder #customerName').val(customerName);
			var contactName = $('#dlg-outorder-new #fm-outorder #contactName').val();
			$('#dlg-outorder-preview #fm-outorder #contactName').val(contactName);
			var operateUser = $('#dlg-outorder-new #fm-outorder #operateUserFullName').val();
			$('#dlg-outorder-preview #fm-outorder #operateUserFullName').val(operateUser);
			var userSignedTo = $('#dlg-outorder-new #fm-outorder #userSignedTo').val();
			$('#dlg-outorder-preview #fm-outorder #userSignedTo').val(userSignedTo);
			var result = $('#dlg-outorder-new #fm-outorder #dg-outorderItem-new').datagrid('getData');
			$('#dlg-outorder-preview #fm-outorder #dg-outorderItem-preview').datagrid('loadData', result.rows);
			var discount = $('#dlg-outorder-new #fm-outorder #discount').numberspinner('getValue');
			$('#dlg-outorder-preview #fm-outorder #discount').val(discount);
			var receivable = $('#dlg-outorder-new #fm-outorder #receivable').numberbox('getValue');
			$('#dlg-outorder-preview #fm-outorder #receivable').val(receivable);
			var comment = $('#dlg-outorder-new #fm-outorder #comment').val();
			$('#dlg-outorder-preview #fm-outorder #comment').val(comment);
		}
		catch(err) 
		{
			$('#dlg-buttons-outorder-preview #submit-outorder-btn').linkbutton('disable');
			setValidateOutorderMsg('<font color="red">' + err + '</font>');
		}
	
	}
	function submitOutOrder() 
	{
		var userSignedTo = $('#dlg-outorder-new #userSignedTo').val();
		if(userSignedTo == '' || userSignedTo == undefined) 
		{
			setValidateOutorderMsg('<font color="red">' + '请检查客户所属业务员！' + '</font>');
			return;
		}
		try 
		{
			accept();
			saveModel('#dg-outorder', '#dlg-outorder-new', '#fm-outorder', null, accept);
		}
		catch(err) 
		{
			setValidateOutorderMsg('<font color="red">' + err + '</font>');
		}
	}
	function setValidateOutorderMsg (msg) 
	{
		$('#dlg-outorder-new #fm-outorder #tb-outorderList #validateOutorderMsg').html(msg);
	}
</script>

	<div style="width:100%; height:430px;">
		<table id="dg-outorder" title="销售单管理" class="easyui-datagrid"
			toolbar="#toolbar-outorder" pagination="true" rownumbers="true" showFooter="true" 
			singleSelect="true" checkOnSelect="true" selectOnCheck="false" fit="true" noHeader="true"  
			fitColumns="true" sortName="<%=ComponentConstants.CREATE_TIME %>" sortOrder="desc" data-options="onClickRow:onClickOutOrderRow, onLoadSuccess:onLoadOutOrderSuccess, onCheckAll:onCheckAllOutOrder, onUncheckAll:onUnCheckOutOrder, onCheck:onCheckAllOutOrder, onUncheck:onUnCheckOutOrder,onBeforeLoad:onBeforeLoadOutOrder, onDblClickRow:onDblClickOutOrderRow">
			<thead>
				<tr>
					<th data-options="field:'ck',checkbox:true"></th>
					<th width="50" data-options="field:'id'"><spring:message code="order.id" /></th>
					<th field="<%=ComponentConstants.CUSTOMER_NAME %>" width="70" sortable="true" data-options="formatter:customerNameFormatter"><spring:message code="order.customer" /></th>
<%-- 					<th field="<%=ComponentConstants.DEAL_MONEY %>" width="50" sortable="true"><spring:message code="order.inDealMoney" /></th> --%>
					<th field="<%=ComponentConstants.RECEIVABLE_MONEY %>" width="50" sortable="true"><spring:message code="order.inDealMoney" /></th>
					<%-- <th field="<%=ComponentConstants.PAID_MONEY %>" width="50" sortable="true" data-options="styler:cellStyler_orderPaidMoney"><spring:message code="order.paidMoney" /></th> --%>
					<th field="<%=ComponentConstants.PROFIT_MONEY %>" width="50" sortable="true" hidden="true"><spring:message code="order.profit" /></th>
					<th field="<%=ComponentConstants.CREATE_TIME %>" width="50" sortable="true"><spring:message code="order.createDate" /></th>
					<%-- <th field="<%=ComponentConstants.PAY_TIME %>" width="50" sortable="true"><spring:message code="order.payDate" /></th> --%>
					<th field="payDeadline" width="50"><spring:message code="order.payDeadline" /></th>
					<th field="userSignedTo" width="50" data-options="formatter:orderUserSignedFormatter"><spring:message code="order.signUserId" /></th>
					<th field="userOperated" width="50" sortable="true">操作员</th>
					<th field="statusCode" width="50" data-options="formatter:orderStatusFormatter, align:'center'"><spring:message code="order.statusCode" /></th>
				</tr>
			</thead>
		</table>
	</div>
	
	<div id="toolbar-outorder" style="padding:5px;height:auto">
		<div>
			<span id="div-outorder-typecode" style="margin-bottom:5px; margin-right:50px">
				<label><input id="typeCode_out" name="outorder_typeCode_mode" type="radio" value="<%=OrderTypeCode.OUT%>" checked="checked" onclick="onSearchOrderByAdvance()">销售出货</label>
				<label><input id="typeCode_out_return" name="outorder_typeCode_mode" type="radio" value="<%=OrderTypeCode.OUT_RETURN%>" onclick="onSearchOrderByAdvance()">销售退货</label>
			</span>
			<span>
				<a href="javascript:void(0)" class="easyui-linkbutton" 
					iconCls="icon-add" plain="true" onclick="newOutOrder()" title="新增销售单">新增销售单</a> 
				<a id="btn-viewOutorder" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
					iconCls="icon-search" plain="true" onclick="viewOutOrder()" title="选择一行查看订单详情或勾选多行查看订单项">查看销售单</a> 
				<a id="btn-deleteOutorder" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
					iconCls="icon-remove" plain="true" onclick="deleteOutOrder()" title="选择一行删除订单">删除销售单</a>
				<!--<a href="javascript:void(0)" class="easyui-linkbutton"
					plain="true" onclick="editModel('#dg-outorder', '#dlg-update-paid', '新增收款', '#dlg-update-paid #fm-outorder', '<c:url value='/outOrder/updatePaid.html' />', updatePaidCallback)" title="">新增收款</a>-->
				<a id="btn-editStatus" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" 
					iconCls="icon-edit" plain="true" onclick="updateOutOrderStatus()" title="选择一行编辑订单状态">编辑状态</a>
			</span>
		</div>
		<!--<span style="float: right; margin-right: 5px">
			<input class="easyui-searchbox" data-options="prompt:'<spring:message code="pleaseInputValue" />',searcher:doSearchOrder" style="width:300px" />
		</span>-->
		<div>
			<span id="orderIdSearchSpan" style="width: 25%; display: inline-block; margin-left: 8px;">
				<form id="outOrderSearchForm" action="">
	            	订单号: <input id="orderId" name="orderId" class="easyui-textbox" style="width:100px">
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" title="查询出库单" onclick="onSearchOrderById()">查询</a>
				</form>
	        </span>
			<span id="advanceSearchSpan" style="width: 70%; display: inline-block;">
				<form id="outOrderSearchForm" action="">
	            	时间: <input id="startDate" name="startDate" class="easyui-datebox" style="width:100px" 
					editable="false" title="开始时间" data-options="onSelect: onSelectStartDate">
	            	- <input id="endDate" name="endDate" class="easyui-datebox" style="width:100px" 
					editable="false" title="结束时间" data-options="onSelect: onSelectStartDate">&nbsp;
					<select id="timeFrame" name="timeFrame" class="easyui-combobox" style="width:80px" panelHeight="auto" editable="false" data-options="onSelect: onSelectTimeFrame">
						<option value="CUSTOMIZE"><%=TimeFrame.CUSTOMIZE.getText () %></option>
						<option value="TODAY" selected="selected"><%=TimeFrame.TODAY.getText () %></option>
						<option value="RECENT_THREE_DAYS"><%=TimeFrame.RECENT_THREE_DAYS.getText () %></option>
						<option value="RECENT_SEVEN_DAYS"><%=TimeFrame.RECENT_SEVEN_DAYS.getText () %></option>
						<option value="RECENT_FIFTEEN_DAYS"><%=TimeFrame.RECENT_FIFTEEN_DAYS.getText () %></option>
						<option value="RECENT_THIRTY_DAYS"><%=TimeFrame.RECENT_THIRTY_DAYS.getText () %></option>
						<option value="CURRENT_MONTH"><%=TimeFrame.CURRENT_MONTH.getText () %></option>
					</select>
	            	&nbsp;
	            	客户: 
	           		<input id="customerId" name="customerId" class="easyui-combobox" style="width:100px" data-options="
						valueField:'id',
						textField:'shortName',
						url:'',
						onSelect: onSelectCustomer,
						mode:'remote', 
						loader:customerLoader, 
						onBeforeLoad: function(param){
							param.customerTypeCode = '0';
							setAutoCompleteUrl ('<c:url value='/customer/getCustomerByShortNameLike.html' />');
						}" />
					<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" title="查询出库单" onclick="onSearchOrderByAdvance()">查询</a>
				</form>
	        </span>
        </div>
	</div>

	<!-- new order dialog -->
	<div id="dlg-outorder-new" class="easyui-dialog"
		style="width: 800px; height: 500px; padding:15px 5px;" closed="true"
		buttons="#dlg-buttons-outorder-new" data-options="modal:true">
		<div style="width:100%;height:100%">
			<form id="fm-outorder" class="fm" style="margin:0 auto;padding:0px;width:100%;height:100%;" method="post" novalidate>
				<div class="divHidden">
					<input id="id" name="id" value="0">
				</div>
				<div class="divHidden">
					<input id="outorder-typeCode" name="typeCode">
				</div>
				<!-- <div class="divHidden">
					<input id="customerId" name="customerBean.id" class="easyui-textbox" />
				</div> -->
				<div class="fitem css-dlg-outorder">
					<div>
						<label><spring:message code="order.customer" />:</label> 
						<!--<input id="customerName" name="customerBean.shortName" class="easyui-textbox" readonly="readonly" required="true" onclick="popupSearchAndSelectCustomerDialog()" title="<spring:message code="order.searchAndSelectCustomer" />" />-->
						<input id="customerId" name="customerBean.id" class="easyui-combobox" data-options="
							valueField:'id',
							textField:'shortName',
							url:'',
							required:true,
							onSelect: onSelectCustomer,
							onChange:onChangeCustomer,
							mode:'remote', 
							loader:customerLoader, 
							onBeforeLoad: function(param){
								param.customerTypeCode = '0';
								setAutoCompleteUrl ('<c:url value='/customer/getCustomerByShortNameLike.html' />');
							} "/>
					</div>
				</div>
				<div class="fitem divHidden">
					<input id="contactId" name="contactBean.id" />
				</div>
				<div class="fitem css-dlg-outorder">
					<div>
						<label>联系人:</label> 
						<input id="contactName" name="contactBean.name" class="easyui-textbox" readonly="readonly" title="不可编辑" />
					</div>
				</div>
				<div class="fitem divHidden">
					<input id="userOperated" name="userOperated" readonly="readonly" title="不可编辑" />
				</div>
				<div class="fitem css-dlg-outorder">
					<div>
						<label>操作员:</label> 
						<input id="operateUserFullName" name="operateUserFullName" class="easyui-textbox" readonly="readonly" title="不可编辑" />
					</div>
				</div>
				
				<div class="divHidden">
					<input id="outorderItemList" name="orderItemList" />
				</div>
				
				<div style="width:100%;float:left">
					<div style="margin:0 auto;width:670px;">
						<table id="dg-outorderItem-new" class="easyui-datagrid" title="<spring:message code="order.items" />" style="width:670px;height:250px;"
								data-options="
									rownumbers: true,
									singleSelect: true,
									toolbar: '#tb-outorderList',
									onClickRow: onClickRow,
									style:{marginBottom:0},
									showFooter: true,
									fitColumns:true
								">
							<thead>
								<tr>
									<th data-options="field:'id',hidden:true"></th>
									<th data-options="field:'goodsId',width:180,
											formatter:function(value,row){
												return row.name;
											},
											editor:{
												type:'combobox',
												options:{
													valueField:'id',
													textField:'nameAndCurrentStock',
													url:'',
													required:true,
													onSelect: onSelectGoods,
													mode:'remote', 
													loader:goodsLoader,
													onBeforeLoad: function(param){
														setAutoCompleteUrl ('<c:url value='/goods/getGoodsByNameLike.html' />');
													}
												}
											}"><spring:message code="order.product" /></th>
									<th data-options="field:'unit',width:40,editor:'text'"><spring:message code="order.unit" /></th>
									<th data-options="field:'unitPrice',width:60,editor:{type:'numberbox',options:{required:true, precision:2, onChange: onChangeUnitPrice}}"><spring:message code="order.unitPrice" /></th>
									<th data-options="field:'amount',width:50,align:'right',editor:{type:'numberbox', options:{required:true, onChange: onChangeAmount}}"><spring:message code="order.amount" /></th>
									<th data-options="field:'sum',width:90,align:'right',editor:{type:'numberbox',options:{precision:2}}"><spring:message code="order.sum" /></th>
									<th data-options="field:'note',width:140,editor:'text'"><spring:message code="order.note" /></th>
									<th data-options="field:'importPrice',hidden:true,editor:'text'"></th>
								</tr>
							</thead>
						</table>
					</div>
				</div>
			 
				<div id="tb-outorderList" style="height:auto">
					<a id="btn-add-orderItem" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" data-options="iconCls:'icon-add',plain:true" onclick="append()"><spring:message code="order.append" /></a>
<%-- 				        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="accept()"><spring:message code="order.accept" /></a> --%>
					<a id="btn-delete-orderItem" href="javascript:void(0)" class="easyui-linkbutton" disabled="true" data-options="iconCls:'icon-remove',plain:true" onclick="removeit()"><spring:message code="order.remove" /></a>
					<span id="validateOutorderMsg"></span>
				</div>
				
				<div class="fitem css-dlg-outorder">
					<div>
						<label>折扣率:</label> 
						<input id="discount" name="discount" class="easyui-numberspinner" value="1.00" data-options="min:0.01,max:1.00,increment:0.02,precision:2,onChange:onChangeDiscount" />
					</div>
				</div>
				<div class="fitem css-dlg-outorder">
					<div>
						<label>折后应付:</label> 
						<input id="receivable" name="receivable" class="easyui-numberbox" data-options="precision:2" />
					</div>
				</div>
				<div class="fitem css-dlg-outorder">
					<div>
						<label><spring:message code="order.signUserId" />:</label> 
						<input id="userSignedTo" name="userSignedTo" class="easyui-textbox" readonly="readonly" title="不可编辑" required="true" />
					</div>
				</div>
				<!-- <div class="fitem css-dlg-outorder">
					<label>实付款:</label> 
					<input id="paidMoney" name="paidMoney" class="easyui-numberbox" style="width:156px" data-options="precision:2" />
				</div> -->
				<div class="fitem css-dlg-outorder" style="width:100%;">
					<div style="width:670px">
						<label>备注:</label>
						<input id="comment" name="comment" class="easyui-textbox" style="width:100%;" />
					</div>
				</div>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-outorder-new">
		<a href="javascript:void(0)" id="preview-outorder-btn" class="easyui-linkbutton" disabled="true"
			iconCls="icon-ok" onclick="previewOutOrder()">预览</a>
		<a href="javascript:void(0)" id="save-outorder-btn" class="easyui-linkbutton c5" disabled="true"
			iconCls="icon-ok" onclick="submitOutOrder()">提交</a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-outorder-new').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	
	<!-- preview new order dialog -->
	<div id="dlg-outorder-preview" class="easyui-dialog"
		style="width: 800px; height: 500px; padding:15px 5px;" closed="true"
		buttons="#dlg-buttons-outorder-preview" data-options="modal:true">
		<div style="width:100%; weight:100%;">
			<form id="fm-outorder" class="fm" style="margin:0 auto;padding:0px;width:650px;height:100%;" method="post" novalidate>
				<div class="divHidden">
					<input id="id" name="id" value="0">
				</div>
				<div class="divHidden">
					<input id="outorder-typeCode" name="typeCode">
				</div>
				<div class="fitem css-dlg-outorder">
					<label><spring:message code="order.customer" />:</label> 
					<input id="customerName" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>联系人:</label> 
					<input id="contactName" readonly="readonly" />
				</div>
				<div class="fitem divHidden">
					<input id="userOperated" name="userOperated" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>操作员:</label> 
					<input id="operateUserFullName" name="operateUserFullName" readonly="readonly" />
				</div>
				
				<table id="dg-outorderItem-preview" class="easyui-datagrid" style="width:650px;height:auto" title="<spring:message code="order.items" />"
						data-options="
							rownumbers: true,
							singleSelect: true,
							style:{marginBottom:10,display:'inline-block'},
							showFooter: true,
							fitColumns:true
						">
					<thead>
						<tr>
							<th data-options="field:'id',hidden:true"></th>
							<th data-options="field:'name',width:180,formatter:goodsNamePreviewFormatter"><spring:message code="order.product" /></th>
							<th data-options="field:'unit',width:40"><spring:message code="order.unit" /></th>
							<th data-options="field:'unitPrice',width:60"><spring:message code="order.unitPrice" /></th>
							<th data-options="field:'amount',width:50,align:'right'"><spring:message code="order.amount" /></th>
							<th data-options="field:'sum',width:90,align:'right'"><spring:message code="order.sum" /></th>
							<th data-options="field:'note',width:140"><spring:message code="order.note" /></th>
						</tr>
					</thead>
				</table>
			 
				<div class="fitem css-dlg-outorder">
					<label>折扣率:</label> 
					<input id="discount" name="discount" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>折后应付:</label> 
					<input id="receivable" name="receivable" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label><spring:message code="order.signUserId" />:</label> 
					<input id="userSignedTo" name="userSignedTo" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder" style="clear:left; width:650px;">
					<label>备注:</label>
					<input id="comment" name="comment" style="width:645px;" readonly="readonly" />
				</div>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-outorder-preview">
		<a href="javascript:void(0)" id="submit-outorder-btn" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-outorder', '#dlg-outorder-new', '#fm-outorder', function() {$('#dlg-outorder-preview').dialog('close');$('#dg-outorder').datagrid('reload');}, accept)">提交</a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-outorder-preview').dialog('close')">返回</a>
	</div>
	
	<!-- view order dialog -->
	<div id="dlg-outorder-view" class="easyui-dialog"
		style="width: 800px; height: 500px; padding: 15px 5px" closed="true"
		buttons="#dlg-buttons-outorder-view" data-options="modal:true">
		<div class="ftitle" style="margin-left: 30px; margin-right: 30px;">销售单&nbsp;-&nbsp;<span id="order-id-span"></span></div>
		<div style="width:100%; weight:100%;">
			<form id="fm-outorder" class="fm" style="margin:0 auto;padding:0px;width:650px;height:100%;" method="post" novalidate>
				<div class="fitem divHidden">
					<input id="id" name="id" value="0">
				</div>
				<div class="fitem divHidden">
					<input id="customerId" name="customerId" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label><spring:message code="order.customer" />:</label> 
					<input id="customerName" name="<%=ComponentConstants.CUSTOMER_NAME %>" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>联系人:</label> 
					<input id="contactName" name="contactName" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>联系电话:</label> 
					<input id="contactPhone" name="contactPhone" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>操作员:</label> 
					<input id="userOperated" name="userOperated" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label><spring:message code="order.signUserId" />:</label> 
					<input id="userSignedTo" name="userSignedTo" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>开单日期:</label> 
					<input id="<%=ComponentConstants.CREATE_TIME %>" name="<%=ComponentConstants.CREATE_TIME %>" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>状态:</label> 
					<input id="statusCode" name="statusCode" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>折扣率:</label> 
					<input id="discount" name="discount" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>折后应付:</label> 
					<input id="receivable" name="receivable" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder">
					<label>实付款:</label> 
					<input id="paidMoney" name="paidMoney" readonly="readonly" />
				</div>
				<div class="fitem css-dlg-outorder" style="clear:left; width:650px;">
					<label>备注:</label>
					<input id="comment" name="comment" style="width:645px;" readonly="readonly" />
				</div>
				
				<table id="dg-outorderItem-view" class="easyui-datagrid" title="<spring:message code="order.items" />" style="width:650px;height:auto"
						data-options="
							rownumbers: true,
							singleSelect: true,
							showFooter: true,
							style:{display:'inline-block'},
							url: '',
							fitColumns:true
						">
					<thead>
						<tr>
							<th data-options="field:'id',hidden:true"></th>
							<th data-options="field:'goodsName',width:180"><spring:message code="order.product" /></th>
							<th data-options="field:'goodsUnit',width:40"><spring:message code="order.unit" /></th>
							<th data-options="field:'<%=ComponentConstants.ORDER_UNIT_PRICE %>',width:60"><spring:message code="order.unitPrice" /></th>
							<th data-options="field:'<%=ComponentConstants.ORDER_AMOUNT %>',width:50,align:'right'"><spring:message code="order.amount" /></th>
							<th data-options="field:'<%=ComponentConstants.ORDER_SUM %>',width:90,align:'right'"><spring:message code="order.sum" /></th>
							<th data-options="field:'comment',width:140"><spring:message code="order.note" /></th>
						</tr>
					</thead>
				</table>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-outorder-view">
		<a href="javascript:void(0)" id="print-outorder-btn" class="easyui-linkbutton"
			iconCls="icon-print" onclick="gotoPrintDialog ()"><spring:message code="print" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-outorder-view').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	
	<!-- 查看多个订单 -->
	<div id="dlg-multi-outorder-view" class="easyui-dialog"
		style="width: 800px; height: 500px; padding: 10px 10px" closed="true"
		buttons="#dlg-buttons-multi-outorder-view" data-options="modal:true">
		<div style="">
			<table id="dg-outorderItem-view" class="easyui-datagrid" title="订单明细" style="width:750px;height:auto"
					data-options="
						rownumbers: true,
						singleSelect: true,
						showFooter: true,
						url: '',
		                fitColumns:true,
		                view:groupview,
		                groupField:'orderId',
		                groupFormatter:orderGroupFormatter
					">
				<thead>
					<tr>
						<th data-options="field:'id',hidden:true"></th>
						<!--<th data-options="field:'orderCreate',width:120"></th>-->
						<th data-options="field:'goodsName',width:150"><spring:message code="order.product" /></th>
						<th data-options="field:'goodsUnit',width:50"><spring:message code="order.unit" /></th>
						<th data-options="field:'<%=ComponentConstants.ORDER_UNIT_PRICE %>',width:80"><spring:message code="order.unitPrice" /></th>
						<th data-options="field:'<%=ComponentConstants.ORDER_AMOUNT %>',width:80"><spring:message code="order.amount" /></th>
						<th data-options="field:'<%=ComponentConstants.ORDER_SUM %>',width:100"><spring:message code="order.sum" /></th>
						<%-- <th data-options="field:'comment',width:160"><spring:message code="order.note" /></th> --%>
					</tr>
				</thead>
			</table>
		</div>
	</div>
	<div id="dlg-buttons-multi-outorder-view">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-multi-outorder-view').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	<!-- 查看多个订单 -->
	
	<!-- update paid money -->
	<div id="dlg-update-paid" class="easyui-dialog"
		style="width: 400px; height: 300px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons-update-paid" data-options="modal:true">
		<div class="ftitle"><spring:message code="order.order" /></div>
		<div style="">
			<form id="fm-outorder" class="fm" method="post" novalidate>
				<div class="fitem divHidden">
					<input id="id" name="id" value="0">
				</div>
				<div id="div-paidMoney" class="fitem">
					<label><spring:message code="order.payMoney" />:</label> 
					<input id="paidMoney" name="paidMoney" class="easyui-numberbox" required="true" />
				</div>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-update-paid">
		<a href="javascript:void(0)" id="update-paid-save" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-outorder', '#dlg-update-paid', '#fm-outorder')"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-update-paid').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	<!-- update paid money -->
	
	<!-- update status -->
	<div id="dlg-update-status" class="easyui-dialog"
		style="width: 340px; height: 370px; padding: 15px 5px" closed="true"
		buttons="#dlg-buttons-update-status" data-options="modal:true">
		<div style="width:100%;height:100%">
			<form id="fm-outorder" class="fm" method="post" style="margin:0 auto;padding:0px;width:100%;height:100%;" novalidate>
				<div class="fitem css-dlg-outorder2">
					<div>
						<label style="color:#606B73">订单号:</label> 
						<input id="id" name="id" readonly="readonly" style="border: none;">
					</div>
				</div>
				<div class="fitem css-dlg-outorder2">
					<div>
						<label style="color:#606B73">客户:</label> 
						<input id="customerName" name="customerName" readonly="readonly" style="border: none;">
					</div>
				</div>
				<div class="fitem css-dlg-outorder2">
					<div>
						<label><spring:message code="order.statusCode" />:</label> 
						<select id="orderStatus" name="statusCode" class="easyui-combobox" editable="false" panelHeight="auto">
							<option value="NEW" selected="selected"><spring:message code="order.option.new" /></option>
							<!--<option value="RETURN"><spring:message code="order.option.return" /></option>-->
							<option value="CANCEL"><spring:message code="order.option.cancel" /></option>
							<option value="FINISHED"><spring:message code="order.option.finished" /></option>
						</select>
					</div>
				</div>
				<div class="fitem css-dlg-outorder2">
					<div>
						<label>备注:</label> 
						<input id="comment" name="comment" class="easyui-textbox" data-options="multiline:true" style="height:100px">
					</div>
				</div>
			</form>
		</div>
	</div>
	<div id="dlg-buttons-update-status">
		<a href="javascript:void(0)" id="" class="easyui-linkbutton"
			iconCls="icon-ok" onclick="saveModel('#dg-outorder', '#dlg-update-status', '#fm-outorder')"><spring:message code="save" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-update-status').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	<!-- update status -->
	
	<!-- print order -->
	<div id="dlg-print-outorder" class="easyui-dialog" title="打印"
		style="width: 800px; height: 500px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons-print-outorder" toolbar="#div-print-outorder-setting" data-options="modal:true">
		<div id="div-print-outorder-edit" style="">
			<div id="div-outorder-header" style="margin-bottom:5px;">
				<div id="div-print-outorder-title" style="height:30px; font-size:20px; font-weight:bold; text-align: center; margin-bottom:10px;">
					<input id="titleHeader" style="width: auto;" />
					<span id="titleSpan"></span>
				</div>
				<table style="width:100%">
					<tr>
						<td width="40%">客户:&nbsp;<span style="width:80%" id="customer"></span></td>
						<td width="30%">联系人:&nbsp;<input style="width:70%" type="text" id="contact" name="contact"/></td>
						<td width="30%">手机:&nbsp;<input style="width:70%" type="text" id="phone" name="phone"/></td>
					</tr>
					<tr>
						<td>地址:&nbsp;<input style="width:80%" type="text" id="address" name="address"/></td>
						<td>开单日期:&nbsp;<span style="width:60%" id="createDate"></span></td>
						<td>订单号:&nbsp;<span style="width:70%" id="orderId"></span></td>
					</tr>
				</table>
			</div>
			<div id="outorder-table" style="margin-bottom:5px;"></div>
			<div id="div-outorder-footer">
				<table style="width:100%">
					<tbody>
						<tr>
							<td width="25%">经手人:&nbsp;<span style="" id="user"></span></td>
							<td width="25%">业务员:&nbsp;<span style="" id="salesman"></span></td>
							<td width="25%">客户签字:&nbsp;<span style="" id="customerSign"></span></td>
							<td width="25%">日期:&nbsp;<span style="" id="signDate"></span></td></tr>
						<tr>
							<td colspan="4"><input style="width:95%" type="text" id="attachment" name="attachment" value="<%=MessageProperties.getConfig (ComponentConstants.PRINT_ORDER_FOOTER) %>"/></td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		<div id="div-print-outorder" style="display:none">
			
		</div>
	</div>
	<div id="div-print-outorder-setting">
		<label><input id="checkMoney" type="checkbox" style="width:20px" onclick="checkPrintPrice(this)">显示金额</label>
	</div>
	<div id="dlg-buttons-print-outorder">
		<a href="javascript:void(0)" id="" class="easyui-linkbutton"
			iconCls="icon-print" onclick="printOrder()"><spring:message code="print" /></a> 
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel" onclick="javascript:$('#dlg-print-outorder').dialog('close')"><spring:message code="cancel" /></a>
	</div>
	<!-- print order -->